package controlSoftware.view;

import java.awt.Image;
import java.awt.image.ImageObserver;
import javax.swing.JLabel;
import controlSoftware.DataProcess.Coordinate;
import controlSoftware.DataProcess.Device;
import controlSoftware.DataProcess.SensorData;
import controlSoftware.DataProcess.SysModel;
import controlSoftware.GUI.*;

/**
 * Controller class for the device icon rendering on main canvas
 * @author Jiaxi
 *
 */
public class viewController implements ImageObserver{
	
	public JLabel deviceLabel;
	public viewController(Device deviceObj)
	{
		// generates a new layered pane on top of the canvas
		deviceLabel = new JLabel(deviceObj.getUser().getIcon());
		mainUI.layerPanel.add(deviceLabel, new Integer(100));
		//deviceLabel.setBounds((int)(SysModel.initCoordinate.getX()), (int)(SysModel.initCoordinate.getY()),30,30);
		//mainUI.layerPanel.add(deviceLabel, new Integer(deviceObj.getId()), JLayeredPane.POPUP_LAYER );
		
		mainUI.mainCanvas.invalidate();
	}
	
	/**
	 * Update the location of the icon display on the main canvas
	 * @param data
	 * @param prev
	 */
	public void updateView(SensorData data, Coordinate prev){
						
		deviceLabel.setBounds((int)(data.getCurrLoc().getX()), (int)(data.getCurrLoc().getY()),30,30);
		//mainUI.mainCanvas.invalidate();

	}
	
	/**
	 * Remove the icon from the layered pane
	 */
	public void clean()
	{
		mainUI.layerPanel.remove(deviceLabel);
	}

	@Override
	public boolean imageUpdate(Image img, int infoflags, int x, int y,
			int width, int height) {
		// TODO Auto-generated method stub
		return false;
	}

}